package xyz.fuqufyb.aec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.fuqufyb.aec.dao.UserTokenMapper;
import xyz.fuqufyb.aec.data.TableResult;
import xyz.fuqufyb.aec.entity.UserToken;
import xyz.fuqufyb.aec.service.IUserTokenService;

import java.util.List;
import java.util.Map;

/**
 * @author 用户: fyb
 * @description class: UserTokenServiceImpl
 * @date 时间: 2021/2/2 17:58
 */
@Service("IUserTokenService")
public class UserTokenServiceImpl implements IUserTokenService {
    @Autowired

    private UserTokenMapper userTokenMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        int i = userTokenMapper.deleteByPrimaryKey(id);

        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public int insertSelective(UserToken record) {

        int i = userTokenMapper.insertSelective(record);

        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public UserToken selectByPrimaryKey(Integer id) {

        UserToken userToken = userTokenMapper.selectByPrimaryKey(id);
        if (userToken != null) {

            return userToken;
        }
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(UserToken record) {

        int i = userTokenMapper.updateByPrimaryKeySelective(record);

        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public TableResult getPageUserToken(Map<String, Object> maps) {

        String page = (String) maps.get("page");
        String limit = (String) maps.get("limit");

        if (page != null && limit != null) {
            PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
            List<UserToken> pageUserToken = userTokenMapper.getPageUserToken(maps);

            PageInfo<UserToken> pageInfo = new PageInfo<>(pageUserToken);

            return TableResult.getTableResultSuccess(pageInfo.getTotal(), pageInfo.getList());
        }

        return TableResult.getTableResultError("参数不能为空");
    }

    @Override
    public int deleteByUserTokenIds(List<Integer> asList) {
        int i = userTokenMapper.deleteByUserTokenIds(asList);
        if (i > 0) {
            return i;
        }
        return 0;
    }
}
